﻿using System;
using System.Windows.Forms;
using Autodesk.Revit.DB;

namespace YJKArch.Utils.SelectMaterial
{
	public class MaterialSelectManager
	{
		public static bool MaterialSelect(Autodesk.Revit.DB.Document doc, string materialName, ref string selMaterialName)
		{
			MaterialManageForm materialManageForm = new MaterialManageForm(doc, materialName);
			if (materialManageForm.ShowDialog() != DialogResult.OK)
			{
				return false;
			}
			ElementId elementId = materialManageForm.SelectedMaterialId();
			Material material = doc.GetElement(elementId) as Material;
			selMaterialName = material.Name;
			return true;
		}

		public static bool MaterialSelect(Autodesk.Revit.DB.Document doc, ElementId materialId, ref ElementId selMaterialId)
		{
			string oldMaterialName = "";
			if (materialId != ElementId.InvalidElementId)
			{
				oldMaterialName = (doc.GetElement(materialId) as Material).Name;
			}
			MaterialManageForm materialManageForm = new MaterialManageForm(doc, oldMaterialName);
			if (materialManageForm.ShowDialog() != DialogResult.OK)
			{
				return false;
			}
			selMaterialId = materialManageForm.SelectedMaterialId();
			return true;
		}
	}
}
